using System;

namespace InfiniTec.Threading
{
	public class CustomResourceConstraint : IResourceConstraint, IEquatable<CustomResourceConstraint>
	{
		private readonly int _AllowedParalellOperations;
		private readonly string _Id;

		public CustomResourceConstraint(string id, int allowedParalellOperations)
		{
			_Id = id;
			_AllowedParalellOperations = allowedParalellOperations;
		}

		public string Id { get { return _Id; } }

		#region IEquatable<CustomResourceConstraint> Members

		public bool Equals(CustomResourceConstraint obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			return Equals(obj._Id, _Id) && obj._AllowedParalellOperations == _AllowedParalellOperations;
		}

		#endregion

		#region IResourceConstraint Members

		public bool Equals(IResourceConstraint other)
		{
			return Equals(other as CustomResourceConstraint);
		}

		public int AllowedParalellOperations { get { return _AllowedParalellOperations; } }

		#endregion

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != typeof (CustomResourceConstraint)) return false;
			return Equals((CustomResourceConstraint) obj);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				return (_Id.GetHashCode() * 397) ^ _AllowedParalellOperations;
			}
		}

		public static bool operator ==(CustomResourceConstraint left, CustomResourceConstraint right)
		{
			return Equals(left, right);
		}

		public static bool operator !=(CustomResourceConstraint left, CustomResourceConstraint right)
		{
			return !Equals(left, right);
		}
	}
}